import React from 'react';
import moment from 'moment';
import {ts2Formatter,renderState} from 'utils';
import { actions } from 'mirrorx';
{/*
可配置化种类：

1、表格头部字段 
    1、列表页表格头部字段集合 mainTableColumn
    2、编辑页表格头部字段集合 childTableColumn

2、编辑框的字段
    1、编辑页 直接显示在页面的编辑字段 FormField
    2、编辑页 需要点击表格的增行弹框编辑的字段 FormTableField
    3. 列表页查询区域  searchField

3.表头部的按钮  headerButtonSets

4.表行尾部按钮  columnButtonSets
*/}

//表头信息

//字段属性

//基本信息
const FormDataHeader = [
    {
        enname: "code",
        zhname: "单据号",
        type: "FormControl",
        edit: false,
    },
    {
        enname: "organizationId",
        showname: "organizationName",
        codename: "organizationCode",
        zhname: "隶属组织",
        type: "RefComponent",
        refname: "organization",
        param:{
            "AUTH_refdim":"organization","AUTH_refcod":" PromoterSalary"
        },
        cascadeName:{
            paramkey: "EQ_organization.id",
            childtype: "DataHeader",
            refKey: "refpk",
            dtoKey: "organizationId",
            offers: "sellareaId",
            resetOffersFlag: true,
        },
        cascadeChildTable:[{
            refKey: "refpk", 
            dtoKey: "organizationId",
            childType:"promoterSalarySon" 
        }],
        edit: true,
        required: true,
    },
    {
        enname: "monthcount",
        zhname: "核算月度",
        type: "DatePicker",
        format:"YYYY-MM",
        edit: true,
        required: true,
    },
    {
        enname: "sellareaId",
        showname: "sellareaName",
        codename: "sellareaCode",
        zhname: "零售片区",
        type: "RefComponent",
        alias:"organizationId",
        refname:"departmentRef",
        param: {
            EQ_enableState: "0",
        },
        edit: true,
        required: true,
    },
    {
        enname: "remarks",
        zhname: "备注",
        type: "FormControl",
        componentClass: "textarea",
        pattern:/^\S*$/,
        message: "不能有空格",
        edit: true,
    },
    {
        enname: "creator",
        zhname: "制单人",
        type: "FormControl",
        hidepage:{0:true},
        edit: false,
    },
    {
        enname: "createTiming",
        zhname: "创建时间",
        type: "DatePicker",
        defaultValue: moment(),
        hidepage:{0:true},
        format:"YYYY-MM-DD",
        edit: false,
    },

    {
        enname:"modifier",
        zhname:"编辑人",
        required: false,
        hidepage:{0:true,1:false,2:false},
        type: "FormControl",
        edit: false
    },
    {
        enname:"modifiedTime",
        zhname:"编辑时间",
        required: false,
        hidepage:{0:true,1:false,2:false},
        type: "DatePicker",
        format:"YYYY-MM-DD",
    },
    {
        enname:"approver",
        zhname:"审核人",
        required: false,
        hidepage:{0:true,1:false,2:false},
        type: "FormControl",
        edit: false
    },
    {
        enname:"approveTime",
        zhname:"审核日期",
        required: false,
        hidepage:{0:true,1:false,2:false},
        type: "DatePicker",
        format:"YYYY-MM-DD",
        edit: false
    },
    {
        enname: "sell",
        zhname: "销售合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },
    {
        enname: "basicSalary",
        zhname: "底薪合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },
    {
        enname: "allowance",
        zhname: "补贴项目合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },
    {
        enname: "commission",
        zhname: "基础提成合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },
    {
        enname: "change",
        zhname: "变动提成合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },
    {
        enname: "areaaddto",
        zhname: "带单合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },
    {
        enname: "taskbonus",
        zhname: "任务奖金合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },
    {
        enname: "senioritypay",
        zhname: "工龄工资合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },
    {
        enname: "overtimecost",
        zhname: "加班费用合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },
    {
        enname: "exc",
        zhname: "正激励合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },
    {
        enname: "lossexc",
        zhname: "负激励合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },
    {
        enname: "minimumsubsidy",
        zhname: "保底补贴合计",
        type: "FormControl",
        // hidepage:{0:true},
    },
    {
        enname: "socialinsurance",
        zhname: "个人社保合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },{
        enname: "accumulationfund",
        zhname: "个人公积金合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },{
        enname: "companysi",
        zhname: "公司社保合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },{
        enname: "companyaf",
        zhname: "公司公积金合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },{
        enname: "overhead",
        zhname: "管理费用合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },{
        enname: "totalwagebill",
        zhname: "工资总额合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },{
        enname: "personalincometax",
        zhname: "个税合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },{
        enname: "accruedwages",
        zhname: "应付工资合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },{
        enname: "netsalary",
        zhname: "实发工资合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },{
        enname: "totalcost",
        zhname: "费用合计",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    },{
        enname: "cost",
        zhname: "费用率",
        type: "FormControl",
        // hidepage:{0:true},
        edit: false,
    }
];
const columnpromoterSalarySon = [
    {
        title: "门店名称",
        dataIndex: "storeName",
        key: "storeName",
        renderType: "refcomponent",
        width:150,
        validate: false,
        required: true,
        filedProps: {
            title: "门店名称",
            refName: "terminal",
            fieldName: "storeName",
            aliasparam: [{
                paramkey: "EQ_organization.id",
                alias: "organizationId",
            }],
            reffields: { refpk: "storeId", refname: "storeName", refcode: "storeCode" }
        },
        fixed:'left'
    },
    {
        title: "姓名",
        dataIndex: "promoterName",
        key: "promoterName",
        renderType: "refcomponent",
        width:150,
        validate: false,
        required: true,
        filedProps: {
            title: "促销员",
            refName: "promoterstRef",
            fieldName: "channelTypeName",
            reffields: { refpk: "promoterId", refname: "promoterName", refcode: "promoterCode" }
        },
        fixed:'left'
    },
    {
        title: "工龄",
        dataIndex: "standing",
        key: "standing",
        renderType: "inputnumber",
        width:90,
        filedProps: {
            precision:2,
            min: 0,
        }
    },
    {
        title: "销售额",
        dataIndex: "sell",
        key: "sell",
        renderType: "inputnumber",
        width:90,
        required:true,
        filedProps: {
            precision:2,
        }
    },
    {
        title: "底薪",
        dataIndex: "basicSalary",
        key: "basicSalary",
        width:90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
            min: 0,
        }
    },
    {
        title: "补贴项目",
        dataIndex: "allowance",
        key: "allowance",
        width:90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
            min: 0,
        }
    },
    {
        title: "基础提成",
        dataIndex: "commission",
        key: "commission",
        width:90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
        }
    },
    {
        title: "变动提成",
        dataIndex: "change",
        key: "change",
        width:90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
        }
    },
    {
        title: "带单",
        dataIndex: "areaaddto",
        key: "areaaddto",
        width:90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
        }
    },
    {
        title: "任务奖金",
        dataIndex: "taskbonus",
        key: "taskbonus",
        width:90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
            min: 0,
        }
    },
    {
        title: "工龄工资",
        dataIndex: "senioritypay",
        key: "senioritypay",
        width:90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
            min: 0,
        }
    },
    {
        title: "加班费用",
        dataIndex: "overtimecost",
        key: "overtimecost",
        width:90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
            min: 0,
        }
    },
    {
        title: "正激励",
        dataIndex: "exc",
        key: "exc",
        width:90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
            min: 0,
        }
    },
    {
        title: "负激励",
        dataIndex: "lossexc",
        key: "lossexc",
        width:90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
            min: 0,
        }
    },
    {
        title: "保底补贴",
        dataIndex: "minimumsubsidy",
        key: "minimumsubsidy",
        width:90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
            min: 0,
        }
    },
    {
        title: "个人社保",
        dataIndex: "socialinsurance",
        key: "socialinsurance",
        width:90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
            min: 0,
        }
    },{
        title: "个人公积金",
        dataIndex: "accumulationfund",
        key: "accumulationfund",
        width:90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
            min: 0,
        }
    },{
        title: "公司社保",
        dataIndex: "companysi",
        key: "companysi",
        width:90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
            min: 0,
        }
    },{
        title: "公司公积金",
        dataIndex: "companyaf",
        key: "companyaf",
        width:90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
            min: 0,
        }
    },{
        title: "管理费用",
        dataIndex: "overhead",
        key: "overhead",
        width:90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
            min: 0,
        }
    },
    {
        title: "参考提成",
        dataIndex: "reference",
        key: "reference",
        width:90
    },
    {
        title: "实发提成",
        dataIndex: "paid",
        key: "paid",
        width:90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
            min: 0,
        }
    },{
        title: "工资总额",
        dataIndex: "totalwagebill",
        key: "totalwagebill",
        width:90,
        // renderType: "inputnumber",
        // filedProps: {
        //     precision:2,
        //     min: 0,
        // }
    },{
        title: "个税",
        dataIndex: "personalincometax",
        key: "personalincometax",
        // width:90,
        // renderType: "inputnumber",
        // filedProps: {
        //     precision:2,
        //     min: 0,
        // }
    },{
        title: "应付工资",
        dataIndex: "accruedwages",
        key: "accruedwages",
        width:90,
        // renderType: "inputnumber",
        // filedProps: {
        //     precision:2,
        //     min: 0,
        // }
    },{
        title: "实发工资",
        dataIndex: "netsalary",
        key: "netsalary",
        width:90,
        // renderType: "inputnumber",
        // filedProps: {
        //     precision:2,
        //     min: 0,
        // }
    },{
        title: "费用合计",
        dataIndex: "totalcost",
        key: "totalcost",
        width:90,
        // renderType: "inputnumber",
        // filedProps: {
        //     precision:2,
        //     min: 0,
        // }
    },{
        title: "费用率",
        dataIndex: "cost",
        key: "cost",
        width:90,
        // renderType: "inputnumber",
        // filedProps: {
        //     precision:2,
        //     min: 0,
        // }
    },
    {
        title: "备注",
        dataIndex: "remarks",
        key: "remarks",
        renderType: "input",
        pattern:/^\S*$/,
        patternMessage: "不能有空格",
        filedProps: {
            maxLenght:200,
        },
    }
]
//表单字段

export const FormField = {
    "DataHeader": {
        "title": "基础信息",

        "Field": FormDataHeader
    },
}

//表格弹框表单字段
export const FormTableField = {
}

//渲染成字表表格的头
export const childTableColumn = {
    "promoterSalarySon": {
        "title": "明细",
        "type": "grid",
        "column": columnpromoterSalarySon
    },
}

//渲染成字表表格的头
export const mainTableColumn = [
    {
        title: "所属组织",
        dataIndex: "organizationName",
        width:120,
        key: "organizationName",
    },
    {
        title: "单据号",
        dataIndex: "code",
        width:120,
        key: "code",
        render: (text, record) => {
            return <a style={{ "cursor": "pointer" }}
                onClick={() => {
                    actions.routing.push(
                        {
                            pathname: 'PromoterSalary-edit',
                            search: `?search_id=${record.id}&btnPageFlag=2`,
                        }
                    );
                    // location.reload();
                }}
            >
                {text}
            </a >;
        }
    },
    {
        title: "创建日期",
        dataIndex: "creationTime",
        width:120,
        key: "creationTime",
        render(text, record, index) {
            return (text ? ts2Formatter(text) : text)
        },
    },
    {
        title: "核算月度",
        dataIndex: "monthcount",
        width:120,
        key: "monthcount",
        render(text, record, index) {
            return (text ? ts2Formatter(parseFloat(text),"month") : text)
        },
    },
    {
        title: "零售片区",
        dataIndex: "sellareaName",
        width:120,
        key: "sellareaName",
    },
    // {
    //     title: "促销员编码",
    //     dataIndex: "promoterCode",
    //     width:120,
    //     key: "promoterCode",
    // },
    // {
    //     title: "门店名称",
    //     dataIndex: "storeName",
    //     width:120,
    //     key: "storeName",
    // },
    {
        title: "审批状态",
        dataIndex: "state",
        width: 90,
        key: "state",
        render: (text, record, index) => {
            return renderState(text);
        }
    },
    {
        title: "制单人",
        dataIndex: "creator",
        width:120,
        key: "creator",
    },
    {
        title: "备注",
        dataIndex: "remarks",
        width:120,
        key: "remarks",
    },
    // {
    //     title: "姓名",
    //     dataIndex: "promoterName",
    //     width:100,
    //     key: "promoterName",
    // },
    {
        title: "工龄",
        dataIndex: "standing",
        width:80,
        key: "standing",
    },
    {
        title: "销售额",
        dataIndex: "sell",
        width: 100,
        key: "sell",
    },
    {
        title: "底薪",
        dataIndex: "basicSalary",
        width: 100,
        key: "basicSalary",
    },
    {
        title: "补贴项目",
        dataIndex: "allowance",
        width: 100,
        key: "allowance",
    },
    {
        title: "基础提成",
        dataIndex: "commission",
        width: 100,
        key: "commission",
    },
    {
        title: "变动提成",
        dataIndex: "change",
        width: 100,
        key: "change",
    },
    {
        title: "带单",
        dataIndex: "areaaddto",
        width: 100,
        key: "areaaddto",
    },
    {
        title: "任务奖金",
        dataIndex: "taskbonus",
        width: 100,
        key: "taskbonus",
    },
    {
        title: "工龄工资",
        dataIndex: "senioritypay",
        width: 100,
        key: "senioritypay",
    },
    {
        title: "加班费用",
        dataIndex: "overtimecost",
        width: 100,
        key: "overtimecost",
    },
    {
        title: "正激励",
        dataIndex: "exc",
        width: 100,
        key: "exc",
    },
    {
        title: "负激励",
        dataIndex: "lossexc",
        width: 100,
        key: "lossexc",
    },
    {
        title: "保底补贴",
        dataIndex: "minimumsubsidy",
        width: 100,
        key: "minimumsubsidy",
    },
    {
        title: "个人社保",
        dataIndex: "socialinsurance",
        width: 100,
        key: "socialinsurance",
    },{
        title: "个人公积金",
        dataIndex: "accumulationfund",
        width: 100,
        key: "accumulationfund",
    },{
        title: "公司社保",
        dataIndex: "companysi",
        width: 100,
        key: "companysi",
    },{
        title: "公司公积金",
        dataIndex: "companyaf",
        width: 100,
        key: "companyaf",
    },{
        title: "管理费用",
        dataIndex: "overhead",
        width: 100,
        key: "overhead",
    },{
        title: "工资总额",
        dataIndex: "totalwagebill",
        width: 100,
        key: "totalwagebill",
    },{
        title: "个税",
        dataIndex: "personalincometax",
        width: 100,
        key: "personalincometax",
    },{
        title: "应付工资",
        dataIndex: "accruedwages",
        width: 100,
        key: "accruedwages",
    },{
        title: "实发工资",
        dataIndex: "netsalary",
        width: 100,
        key: "netsalary",
    },{
        title: "费用合计",
        dataIndex: "totalcost",
        width: 100,
        key: "totalcost",
    },{
        title: "费用率",
        dataIndex: "cost",
        width: 100,
        key: "cost",
    },{
        title: "备注",
        dataIndex: "remarks",
        width: 150,
        key: "remarks",
    }
]

export const searchField = [
    {
        enname: "organizationId",
        zhname: "隶属组织",
        multiple:false,
        // realRef:true,
        param:{
            "AUTH_refdim":"saleOrg","AUTH_refcod":"retail_order"
        },
        cascadeName: [{
            paramkey: "EQ_organization.id",
            childtype: "DataHeader",
            refKey: "refpk",
            dtoKey: "organizationId",
            offers: "promoterSalarySon&storeId",
            resetOffersFlag: true,
        },{
            paramkey: "EQ_organization.id",
            childtype: "DataHeader",
            refKey: "refpk",
            dtoKey: "organizationId",
            offers: "sellareaId",
            resetOffersFlag: true,
        }],
        type: "RefComponent",
        refname:"organization",
        edit:true,
    },
    {
        enname: "promoterSalarySon&storeId",
        zhname: "门店",
        required: false,
        alias:"organizationId",
        refname: "terminal",
        multiple: true,
        type: "RefComponent",
        edit: true
    },
    {
        enname:"state",
        zhname:"审批状态",
        required: false,
        code:"BILL_STATUS",
        type: "Select",
        edit: true
    },
    {
        enname: "promoterSalarySon&promoterId",
        zhname: "促销员",
        required: false,
        refname: "promoterstRef",
        multiple: true,
        type: "RefComponent",
        edit: true
    },
    {
        enname: "monthcount",
        zhname: "核算月度",
        required: false,
        type: "RangePicker",
        rangeField: ["creationTime", "creationTime"],
        edit: true
    },
    {
        enname: "sellareaId",
        zhname: "零售片区",
        alias: "organizationId",
        required: false,
        refname:"departmentRef",
        type: "RefComponent",
        edit: true
    },
    {
        enname: "makerId",
        zhname: "制单人",
        type: "RefComponent",
        refname:"promoterstRef",
        edit: true
    },
    {
        enname:"remarks",
        codename:"ownerShopCode",
        showname:"ownerShopName",
        zhname:"备注",
        required: false,
        refname:"shopref",
        type: "RefComponent",
        edit: true
    }
]

export const headerButtonSets = [
    {
        event: "ButtonAdd",
        zhname: "新增",
        color: 'primary',
        authcode: "Salaryadd",
    }
]

export const columnButtonSets = {
    "delete": {
        event: "ButtonDel",
        zhname: "删除",
        batch: true,
        method: "post",
        ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
        url: 'occ-base/base/promoter-salarys/deleteout'
    },
    "edit": true,
    "detail": true
}

// export default {mainTableColumn,searchField,headerButtonSets,
//     columnButtonSets,childTableColumn,FormTableField,FormField}
export const SelectCode = ["QY132","ls002","ls001","sale","BILL_STATUS"]
